import Form, { FormInstance } from 'antd/lib/form';
import { ModalFuncProps } from 'antd/lib/modal';
import confirm from 'antd/lib/modal/confirm';
import React, { Component } from 'react';

interface IConfirmPlusProps extends ModalFuncProps {
	formData?: Record<string, any>;
	okText?: string;
	cancelText?: string;
	content: (form: FormInstance) => React.ReactNode;
}

export default function ConfirmPlus(props: IConfirmPlusProps) {
	const [form] = Form.useForm();
	form.setFieldsValue(props.formData || {});

	confirm({
		title: props.title,
		icon: props.icon,
		okText: props.okText || '确定',
		cancelText: props.cancelText || '取消',
		content: props.content(form),
		onOk() {
			return new Promise((resolve, reject) => {
				reject(new Error('err'));
				// form.validateFields()
				// 	.then((values) => {
				// 		resolve();
				// 	})
				// 	.catch((info) => {
				// 		console.log('Validate Failed:', info);
				// 		reject(info);
				// 	});
			}).catch(() => console.log('Oops errors!'));
		},
		onCancel() {},
	});
}
